﻿// The MIT License (MIT)
// Copyright (c) 2014 Grégory Ghez
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

namespace JenkinsController.Tests.Framework
{
    using System;
    using System.Globalization;
    using System.Windows.Data;
    using System.Windows.Media;
    using Jenkins.Domain;
    using JenkinsController.Framework;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Ploeh.AutoFixture;

    [TestClass]
    public class JenkinsJobStatusToBrushConverterTests
    {
        private readonly Fixture defaultFixture = new Fixture();

        private IValueConverter converter;

        [TestInitialize]
        public void InitContext()
        {
            this.converter = new JenkinsJobStatusToBrushConverter();
        }

        [TestMethod]
        [ExpectedException(typeof(NotImplementedException))]
        public void Invoke_ConvertBack_ShouldThrowException()
        {
            this.converter.ConvertBack(default(object), typeof(object), default(object), default(CultureInfo));
        }

        [TestMethod]
        public void Invoke_Convert_OnNullValue_ShouldReturnGrayBrush()
        {
            Assert.IsNull(this.converter.Convert(null, typeof(object), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_OnIntegerType_ShouldReturnGrayBrush()
        {
            Assert.IsNull(this.converter.Convert(this.defaultFixture.Create<int>(), typeof(int), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_OnStringType_ShouldReturnGrayBrush()
        {
            Assert.IsNull(this.converter.Convert(this.defaultFixture.Create<string>(), typeof(string), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_OnDateTimeType_ShouldReturnGrayBrush()
        {
            Assert.IsNull(this.converter.Convert(this.defaultFixture.Create<DateTime>(), typeof(string), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_OnTimeSpanType_ShouldReturnGrayBrush()
        {
            Assert.IsNull(this.converter.Convert(this.defaultFixture.Create<TimeSpan>(), typeof(string), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_OnJenkinsBuildStatusType_ShouldReturnGrayBrush()
        {
            Assert.IsNull(this.converter.Convert(JenkinsBuildStatus.Success, typeof(JenkinsBuildStatus), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_WithNullStatus_ShouldReturnGrayBrush()
        {
            Assert.IsNull(this.converter.Convert(null, typeof(JenkinsJobStatus), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_WithFailedStatus_ShouldReturnRedBrush()
        {
            Assert.AreEqual(Brushes.Red, this.converter.Convert(new JenkinsJobStatus { State = JenkinsJobState.Failed }, typeof(JenkinsJobStatus), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_WithUnstableStatus_ShouldReturnOrangeBrush()
        {
            Assert.AreEqual(Brushes.Orange, this.converter.Convert(new JenkinsJobStatus { State = JenkinsJobState.Unstable }, typeof(JenkinsJobStatus), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_WithFailedStatus_ShouldReturnGreenBrush()
        {
            Assert.AreEqual(Brushes.Green, this.converter.Convert(new JenkinsJobStatus { State = JenkinsJobState.Success }, typeof(JenkinsJobStatus), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_WithNoneStatus_ShouldReturnGrayBrush()
        {
            Assert.AreEqual(Brushes.Gray, this.converter.Convert(new JenkinsJobStatus { State = JenkinsJobState.None }, typeof(JenkinsJobStatus), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_WithDisabledStatus_ShouldReturnGrayBrush()
        {
            Assert.AreEqual(Brushes.Gray, this.converter.Convert(new JenkinsJobStatus { State = JenkinsJobState.Disabled }, typeof(JenkinsJobStatus), null, null));
        }

        [TestMethod]
        public void Invoke_Convert_WithAbortedStatus_ShouldReturnGrayBrush()
        {
            Assert.AreEqual(Brushes.Gray, this.converter.Convert(new JenkinsJobStatus { State = JenkinsJobState.Aborted }, typeof(JenkinsJobStatus), null, null));
        }
    }
}